// Hermite插值函数
double Hermite(double* x, double* y, double* m, int n, double a) {
    double* l = new double[n];
    for (int i = 0; i < n; i++) {
        l[i] = 1.0;
        for (int k = 0; k < n; k++) { // 注意这里应该是 k < n 而不是 k <= n
            if (k != i) {
                l[i] *= (a - x[k]) / (x[i] - x[k]);
            }
        }
    }

    double* d = new double[n];
    for (int i = 0; i < n; i++) {
        d[i] = 0.0;
        for (int k = 0; k < n; k++) { 
            if (k != i) {
                d[i] += 1.0 / (x[i] - x[k]);
            }
        }
    }

    double result = 0.0;

    for (int i = 0; i < n; i++) {
        double h_i = (1.0 - 2.0 * (a - x[i]) * d[i]) * l[i] * l[i];
        double s_i = (a - x[i]) * l[i] * l[i];
        result += y[i] * h_i + m[i] * s_i;
    }

    delete[] l;
    delete[] d;

    return result;
}
